import pika

# 连接到 RabbitMQ 服务器
connection = pika.BlockingConnection(
    pika.ConnectionParameters(
        host='10.10.2.236',  # RabbitMQ 服务器的地址
        port=31331,  # RabbitMQ 服务器的端口
        credentials=pika.PlainCredentials(
            username='admin',  # 替换为你的 RabbitMQ 用户名
            password='Parav1ew!'  # 替换为你的 RabbitMQ 密码
        )
    )
)
channel = connection.channel()

# 声明交换器
exchange_name = ''
exchange_type = 'direct'  # 可以是 direct, topic, fanout, headers
channel.exchange_declare(exchange=exchange_name, exchange_type=exchange_type, durable=True)

# 声明队列
queue_name = 'DRS00003'
channel.queue_declare(queue=queue_name, durable=True)

# 绑定队列到交换器，并指定路由键
routing_key = 'ID0'
channel.queue_bind(exchange=exchange_name, queue=queue_name, routing_key=routing_key)

print(f"队列 '{queue_name}' 已成功绑定到交换器 '{exchange_name}'，路由键为 '{routing_key}'")

# 关闭连接
connection.close()
